﻿/*============================================
 * 类名 :Calculator
 * 描述 :
 *   
 * 创建时间: 2011-2-2 11:44:55
 * Blog:   http://home.cnblogs.com/xiangism
 *============================================*/
using System;
using System.Collections.Generic;

using System.Text;
using System.Windows.Forms;

namespace SuperCalculator
{
    /// <summary></summary>
    public class Calculator : MathAssistLibrary.ICommand
    {

        string MathAssistLibrary.ICommand.Describe {
            get { return "cal命令可以进行相关的数学运算。比如cal 1+max(2,3)*2"; }
        }

        string MathAssistLibrary.ICommand.Excute(string cmd) {
            try {
                Expression exp = new Expression();
                exp.Format = cmd;
                return exp.Calculator().ToString();
            } catch (ExpressionException e) {
                return string.Format("表达式出错。出错类型:{0},出错位置{1}", e.Message, e.Index);
            }
        }

        string MathAssistLibrary.ICommand.Name {
            get { return "cal"; }
        }
    }
}
